//package com.sgb.member.weight;
//
//import android.annotation.SuppressLint;
//import android.content.Context;
//import android.text.Editable;
//import android.text.TextUtils;
//import android.text.TextWatcher;
//import android.util.SparseArray;
//import android.view.View;
//import android.widget.EditText;
//import android.widget.TextView;
//
//import androidx.annotation.NonNull;
//import androidx.recyclerview.widget.LinearLayoutManager;
//import androidx.recyclerview.widget.RecyclerView;
//import com.sgb.member.BR;
//import com.sgb.member.R;
//import com.sgb.member.entity.BusinessPriceBean;
//import com.sgb.member.entity.MemberCompanyTeamBean;
//import com.sgb.member.entity.MemberGoodsListEntity;
//import com.sgb.member.entity.MemberLeaseBean;
//import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
//import com.swgk.core.recyclerview.adapter.ItemViewHolder;
//import com.swgk.core.util.ClickUtils;
//import com.swgk.core.util.MToast;
//import com.swgk.core.util.StringUtil;
//import com.lxj.xpopup.core.CenterPopupView;
//
//import java.text.NumberFormat;
//import java.util.ArrayList;
//import java.util.List;
//
//@SuppressLint("ViewConstructor")
//public class MemberBusinessPricePopup extends CenterPopupView {
//
//    private final int mCurPos;
//    private Object mObject;
//    private List<BusinessPriceBean> list = new ArrayList<>();
//
//    public MemberBusinessPricePopup(@NonNull Context context, int curPos, Object entity, OnConfirmListener confirmListener) {
//        super(context);
//        mCurPos = curPos;
//        mObject = entity;
//        setConfirmListener(confirmListener);
//    }
//
//    @Override
//    protected int getImplLayoutId() {
//        return R.layout.dialog_member_business_price;
//    }
//
//    @Override
//    protected void onCreate() {
//        super.onCreate();
//        findViewById(R.id.tv_action2).setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (!ClickUtils.isDoubleClick()) {
//                    dismiss();
//                }
//            }
//        });
//        findViewById(R.id.iv_close).setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (!ClickUtils.isDoubleClick()) {
//                    dismiss();
//                }
//            }
//        });
//        findViewById(R.id.tv_action3).setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (!ClickUtils.isDoubleClick()) {
//                    for (BusinessPriceBean bean : list) {
//                        if (bean.isEdit) {
//                            if (TextUtils.isEmpty(bean.value)) {
//                                MToast.showToast(getContext(), "请输入报价价格");
//                                return;
//                            } else {
//                                dismiss();
//                                if (confirmListener != null) {
//                                    confirmListener.onConfirm(bean.value);
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        });
//
//        TextView textView = findViewById(R.id.tv_title);
//        RecyclerView recyclerView = findViewById(R.id.recycler_view);
//        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
//        switch (mCurPos) {
//            case 0:
//                MemberGoodsListEntity entity = (MemberGoodsListEntity) mObject;
//                textView.setText("商品调整经营");
//                list.add(new BusinessPriceBean("商品", entity.getCartTitle(), false));
//                list.add(new BusinessPriceBean("品牌", entity.getBrandName(), false));
//                list.add(new BusinessPriceBean("仓储地", entity.getStorageName(), false));
//                list.add(new BusinessPriceBean("单位", entity.getUnit(), false));
//                list.add(new BusinessPriceBean("单价 （元）", price(entity.getPrice()), false));
//                list.add(new BusinessPriceBean("报价（元）", "", true));
//                break;
//            case 1:
//                MemberLeaseBean leaseBean = (MemberLeaseBean) mObject;
//                textView.setText("租赁调整经营");
//                list.add(new BusinessPriceBean("出租内容", leaseBean.getTitle(), false));
//                list.add(new BusinessPriceBean("类目", leaseBean.getCategory(), false));
//                list.add(new BusinessPriceBean("所在地", leaseBean.getAddress(), false));
//                list.add(new BusinessPriceBean("单位", leaseBean.getPriceUnit(), false));
//                list.add(new BusinessPriceBean("单价 （元）", price(Double.parseDouble(leaseBean.getPrice())), false));
//                list.add(new BusinessPriceBean("报价（元）", "", true));
//                break;
//            case 2:
//                MemberCompanyTeamBean findBean = (MemberCompanyTeamBean) mObject;
//                textView.setText("工队调整经营");
//                list.add(new BusinessPriceBean("工种名称", StringUtil.getNotEmptyStr(findBean.getType_work_name()), false));
//                list.add(new BusinessPriceBean("工程分类", StringUtil.getNotEmptyStr(findBean.getCategory()), false));
//                switch (findBean.getHas_material()) {
//                    case 0:
//                        //:包含辅材
//                        list.add(new BusinessPriceBean("报价方案", "包含辅材", false));
//                        list.add(new BusinessPriceBean("包含辅材", StringUtil.getNotEmptyStr(findBean.getMaterial()), false));
//                        break;
//                    case 1:
//                        //:不包含辅材
//                        list.add(new BusinessPriceBean("报价方案", "不包含辅材", false));
//                        break;
//                    case 2:
//                        //:包含辅材和设备
//                        list.add(new BusinessPriceBean("报价方案", "包含辅材和设备", false));
//                        list.add(new BusinessPriceBean("包含辅材", StringUtil.getNotEmptyStr(findBean.getMaterial()), false));
//                        break;
//                    case 3:
//                        //:不包含辅材和设备
//                        list.add(new BusinessPriceBean("报价方案", "不包含辅材和设备", false));
//                        break;
//                }
//                list.add(new BusinessPriceBean("计量单位", StringUtil.getNotEmptyStr(findBean.getUnit()), false));
//                list.add(new BusinessPriceBean("所在地区", StringUtil.getNotEmptyStr(findBean.getAddress()), false));
//                list.add(new BusinessPriceBean("单价 （元）", price(Double.parseDouble(findBean.getPrice())), false));
//                list.add(new BusinessPriceBean("报价（元）", "", true));
//                break;
//        }
//        myTextWatchers = new SparseArray<>();
//        recyclerView.setAdapter(new BaseRecycleAdapter<BusinessPriceBean>(getContext(), R.layout.dialog_member_business_price_item, list) {
//            @Override
//            public void convert(ItemViewHolder holder, BusinessPriceBean o) {
//                holder.setBinding(BR.viewModel, o);
//            }
//
//            @Override
//            public void onBindViewHolder(ItemViewHolder holder, int position) {
//                super.onBindViewHolder(holder, position);
//                EditText editText = holder.itemView.findViewById(R.id.et_price);
//                editText.setTag(position);
//                if (myTextWatchers.get(position) == null) {
//                    myTextWatchers.put(position, new MyTextWatcher(datas.get(position)));
//                }
//                editText.removeTextChangedListener(myTextWatchers.get(position));
//                editText.addTextChangedListener(myTextWatchers.get(position));
//            }
//        });
//    }
//
//    public String price(double price){
//        NumberFormat nf = NumberFormat.getInstance();
//        nf.setGroupingUsed(false);
//        nf.setMinimumFractionDigits(2);
//        nf.setMaximumFractionDigits(2);
//        return nf.format(price);
//    }
//
//    private SparseArray<MyTextWatcher> myTextWatchers;
//
//    static class MyTextWatcher implements TextWatcher {
//
//        private final BusinessPriceBean bean;
//
//        public MyTextWatcher(BusinessPriceBean bean) {
//            this.bean = bean;
//        }
//
//        @Override
//        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//        }
//
//        @Override
//        public void onTextChanged(CharSequence s, int start, int before, int count) {
//            if (!TextUtils.isEmpty(s)) {
//                bean.value = s.toString().trim();
//            } else {
//                bean.value = "";
//            }
//        }
//
//        @Override
//        public void afterTextChanged(Editable s) {
//
//        }
//    }
//
//
//    private OnConfirmListener confirmListener;
//
//    public void setConfirmListener(OnConfirmListener confirmListener) {
//        this.confirmListener = confirmListener;
//    }
//
//    public interface OnConfirmListener {
//        void onConfirm(Object o);
//    }
//}
